import { BattleRole } from "../role/BattleRole";
import { ITriggerResult } from "../trigger/const/ITriggerResult";
import { TriggerType } from "../trigger/const/TriggerType";
import { TriggerBase } from "../trigger/TriggerBase";
import { TriggerMgr } from "../trigger/TriggerMgr";
import { SkillData } from "./const/SkillData";

/**
 * 技能释放实体
 */
export class SkillBase {
    skillData: SkillData;
    constructor(data: SkillData) {
        this.skillData = data;
    }

    init(caster: BattleRole, targets: BattleRole[]) {
        let triggerDatas = this.skillData.triggerDatas;
        for (let one of triggerDatas) {
            let trigger = new TriggerBase(one)
            caster.triggerMgr.registerTrigger(trigger);
            if (trigger.maxActivations == -2) {//如果是-2，则表示和目标数量一样
                trigger.maxActivations = targets.length;
            }
        }
    }

    /**释放技能 */
    excute(caster: BattleRole, target: BattleRole): any {
        let oneResult = {
            caster: caster,
            target: target,
            results: []
        }
        //伤害计算前
        caster.triggerMgr.trigger(TriggerType.beforeAttack, oneResult)
        target.triggerMgr.trigger(TriggerType.beforeAttack, oneResult)
        //伤害计算
        caster.triggerMgr.trigger(TriggerType.attackStart, oneResult)
        //伤害计算后
        caster.triggerMgr.trigger(TriggerType.attackEnd, oneResult)
        return oneResult
    }
}